
--[[
自动锁定攻击单位释放
]]
local mt = ac.skill['自动释放']
mt.art = [[ReplaceableTextures\CommandButtons\BTNOrbOfLightning.blp]]
mt.cool = 0     --冷却时间
mt.odds = 100   --触发几率
mt.bind = nil   --绑定技能

function mt:on_add()
    local hero = self.owner
    self.bind_skill = self
    self.lock_unit = nil
    self.lock_time = 0
    if self.bind then
        self.bind_skill = hero:add_skill(self.bind,'隐藏')
        self:gc(self.bind_skill)
    end
    self:notify('on_init',hero)
    self:gc(hero:add_buff '自动技能逻辑'{})
    self:gc(hero:event '单位-触发自动'(function(_,_,target)
        if self:is_cooling()==false then
            self:active_cd()
            self:notify('on_run',hero,target,self.bind_skill)
            return true
        end
    end))
end

--兼容被动端口
function mt:on_run(hero,target,temp)
    temp.target = target
    temp:notify('on_cast_shot')
end



local buff = ac.buff['自动技能逻辑']
buff.cover_type = 1
buff.cover_max = 1
buff.keep = 1
buff.pulse = 0.1
buff.lock_time = 0

function buff:on_add()
    local hero = self.owner
    self:gc(hero:event '单位-攻击命中'(function(_,_,target)
        self.lock_unit = target
        self.lock_time = ac.clock() + 1000
    end))
end

function buff:on_pulse()
    local hero = self.owner
    if self.lock_time>=ac.clock() then
        hero:dispatch('单位-触发自动',hero,self.lock_unit)
    end
end